home *** CD-ROM | disk | FTP | other *** search
- #include <Shutdown.h>
- #include <Icons.h>
- #include <Folders.h>
- #include <Gestalt.h>
-
- #pragma macsbug off
-
- //#include <SetUpA4.h>
- //#include <A4Stuff.h>
- long SetCurrentA4(void);
- long GetCurrentA4(void) = 0x200C;
- void Flush68KCodeCaches(void) = 0xA0BD;
-
- #include "Blitter.h"
-
- extern struct Keyboard {
- short wasted;
- short wasted2;
- short wasted3;
- int command : 1;
- int : 5;
- int space : 1;
- int tab : 1;
- int : 4;
- int control : 1;
- int option : 1;
- int capslock : 1;
- int shift : 1;
- } keymap : 0x174;
-
- // SetA4 is an inline for setting register a4 without using inline assembly.
- // it returns the old value of a4.
-
- #pragma parameter __A0 SetA4(__A0)
- pascal void *SetA4(void *newA4) = 0xC948;
-
- // iRelString is an interface to the RelString trap. It returns a result such
- // that "iRelString(s1, s2) > 0" returns the same as "s1 > s2", that is, zero
- // if the strings are equal, 1 if s1 is greater that s2, -1 if neither.
-
- #pragma parameter __D0 iRelString(__A0, __A1)
- pascal short iRelString(void *first, void *second) = {
- 0x7000, // moveq #0,d0
- 0x1018, // move.b (a0)+,d0
- 0x4840, // swap d0
- 0x1019, // move.b (a1)+,d0
- 0xA050 // RelString
- };
-
- QDGlobals qd;
-
- pascal void InitGame();
-
- #define CurApNameTest tst.b 0x910
-
- //
- // QuickSilver.main.c
- //
- // Note: one concept was to patch HGetState etc. to the real minimum instructions required;
- // need to investigate when and where that's possible.
- //
-
- void realmain(Handle code);
-
- pascal OSErr IconCatcher(OSType selector,long *response);
-
- // main has to be the first function in this file for our
- // technique of setting up A4 to work.
- void main(void) {
- void *oldA4;
- Handle h;
- long codeLength;
- long i;
-
- if (keymap.shift) return;
-
- oldA4 = (void *)SetCurrentA4(); // set up access to Metrowerks C globals
- h = Get1IndResource('INIT', 1);
- codeLength = GetHandleSize(h);
-
- for (i = 0; i < codeLength; i += 2) {
- if (*(short *)(*h + i) == 0x49F9) {
- i += 2;
- if (*(long *)(*h + i) == 0x23700732) {
- *(long *)(*h + i) = GetCurrentA4();
- }
- }
- }
- Flush68KCodeCaches();
-
- realmain(h);
- InitGame();
-
- SetA4(oldA4);
- }
-
- void *lastValidINITName;
-
- static asm void pGet1IndRes(void) {
- tst.l 0x914
- ble.s @oldGet1IndRes
-
- move.l a4,-(a7)
- lea 0x23700732,a4
- move.l 0x914,lastValidINITName
- move.l (a7)+,a4
- @oldGet1IndRes:
- }
- static asm void oldGet1IndRes(void) {
- jmp 0x12345678
- }
-
- static long loaded_file_nums[1024];
-
- static pascal void CloseAResFile(short refNum) {
- Handle h;
- short oldResLoad, oldROMMapInsert, oldResError;
- short ID;
-
- long *rover;
- long filenum;
- long limit;
-
- if (*(long *)0x914 > 0) return; // only when INITs are being closed by the INIT loader
-
- filenum = *(long *)(*(long *)0x34E + refNum);
- if (iRelString((void *)(*(long *)0x34E + refNum + 0x3E), lastValidINITName)) {
- // *(void **)0x40 = (void *)(*(long *)0x34E + refNum + 0x3E);
- // DebugStr("\pNot what we want??;dm 40^;dm 914^");
- return;
- }
-
- for (rover = loaded_file_nums; *rover;) {
- if (*rover++ == filenum) return;
- }
- *rover = filenum;
-
- oldResError = *(short *)0xA60;
-
- UseResFile(refNum);
-
- oldResLoad = *(short *)0xA5E;
- oldROMMapInsert = *(short *)0xB9E;
- SetResLoad(1);
- h = Get1IndResource('BNDL', 1);
- if (h) {
- rover = (long *)*h;
- limit = GetHandleSize(h);
- while (limit > 4) {
- limit -= 2;
- rover = (long *)(2 + (long)rover);
- if (*rover == 'ICN#') {
- ID = *(short *)(8 + (long)rover);
- // ShowINIT(ID);
- Blit(ID);
- break;
- }
- }
- }
- *(short *)0xA5E = oldResLoad;
- *(short *)0xB9E = oldROMMapInsert;
-
- *(short *)0xA60 = oldResError;
- }
-
- // pascal void CloseResFile(short refNum)
-
- static asm void pCloseResFile(void) {
- tst.b 0x910
- bgt.s @oldCloseResFile
- movem.l d0-d2/a0-a1/a4,-(a7)
- lea 0x23700732,a4
- move.w 28(a7),-(a7)
- jsr CloseAResFile
- movem.l (a7)+,d0-d2/a0-a1/a4
- @oldCloseResFile:
- }
- static asm void oldCloseResFile(void) {
- jmp 0x12345678
- }
-
- // pascal void FillRect(Rect *r, Pattern *pat);
-
- static asm pascal void pFillRect(Rect *r, Pattern *pat) {
- move.l a4,-(a7)
- lea 0x23700732,a4
- // if (*(char *)0x910 > 0 || *(char *)0x914 != -1) {
- // oldFillRect(r, pat);
- // }
- tst.b 0x910
- bgt.s @doFill
- cmpi.b #-1,0x914
- bne.s @doFill
- move.l (a7)+,a4
- move.l (a7)+,(a7)
- move.l (a7)+,(a7)
- rts
- @doFill:
- move.l (a7)+,a4
- }
- static asm void oldFillRect(void) {
- jmp 0x12345678
- }
-
- // pascal void FrameRect(Rect *r);
-
- static asm pascal void pFrameRect(Rect *r) {
- move.l a4,-(a7)
- lea 0x23700732,a4
- // if (*(char *)0x910 > 0 || *(char *)0x914 != -1) {
- // oldFillRect(r, pat);
- // }
- tst.b 0x910
- bgt.s @doFrame
- cmpi.b #-1,0x914
- bne.s @doFrame
- move.l (a7)+,a4
- move.l (a7)+,(a7)
- rts
- @doFrame:
- move.l (a7)+,a4
- }
- static asm void oldFrameRect(void) {
- jmp 0x12345678
- }
-
- // pascal void CopyMask(BitMap *srcBits, BitMap *maskBits, BitMap *dstBits, Rect *srcRect, Rect *maskRect, Rect *dstRect)
-
- static asm void pCopyMask(void) {
- movem.l d0/a0/a1/a4,-(a7)
- lea 0x23700732,a4
-
- CurApNameTest
- bgt @not_what_we_want
-
- clr.l -(a7)
- pea (a7)
- dc.w 0xA870 // _LocalToGlobal
- tst.l (a7)+
- bne @not_what_we_want
-
- move.l 20(a7),a0 // a0 = dstRect
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
-
- move.l 28(a7),a0 // a0 = srcRect
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
-
- lea @junkRect,a0
- move.l a0,20(a7) // replace dstRect with zero so the icon won't show up.
-
- @not_what_we_want:
- movem.l (a7)+,d0/a0/a1/a4
- bra.s @oldCopyMask
- @junkRect:
- dc.w 0,0,0,0
- @oldCopyMask:
- }
- static asm void oldCopyMask(void) {
- jmp 0x12345678
- }
-
- // pascal void CopyBits(BitMap *srcBits, BitMap *dstBits, Rect *srcRect, Rect *dstRect, short mode, RgnHandle maskRgn)
-
- static asm void pCopyBits(void) {
- movem.l d0/a0/a1/a4,-(a7)
- lea 0x23700732,a4
-
- CurApNameTest
- bgt @not_what_we_want
-
- clr.l -(a7)
- pea (a7)
- dc.w 0xA870 // _LocalToGlobal
- tst.l (a7)+
- bne @not_what_we_want
-
- move.l 26(a7),a0 // a0 = dstRect
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
-
- move.l 30(a7),a0 // a0 = srcRect
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
-
- lea @junkRect,a0
- move.l a0,26(a7) // replace dstRect with zero so the icon won't show up.
-
- @not_what_we_want:
- movem.l (a7)+,d0/a0/a1/a4
- bra.s @oldCopyBits
- @junkRect:
- dc.w 0,0,0,0
- @oldCopyBits:
- }
- static asm void oldCopyBits(void) {
- jmp 0x12345678
- }
-
- // pascal void PlotIcon(Rect *theRect, Handle theIcon)
-
- static asm void pPlotIcon(void) {
- movem.l d0/a0/a1/a4,-(a7)
- lea 0x23700732,a4
-
- CurApNameTest
- bgt @not_what_we_want
-
- clr.l -(a7)
- pea (a7)
- dc.w 0xA870 // _LocalToGlobal
- tst.l (a7)+
- bne @not_what_we_want
-
- move.l 24(a7),a0 // a0 = dstRect
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
-
- lea @junkRect,a0
- move.l a0,24(a7) // replace dstRect with zero so the icon won't show up.
-
- @not_what_we_want:
- movem.l (a7)+,d0/a0/a1/a4
- bra.s @oldPlotIcon
- @junkRect:
- dc.w 0,0,0,0
- @oldPlotIcon:
- }
- static asm void oldPlotIcon(void) {
- jmp 0x12345678
- }
-
- // pascal void PlotCIcon(Rect *theRect, CIconHandle theIcon)
-
- static asm void pPlotCIcon(void) {
- movem.l d0/a0/a1/a4,-(a7)
- lea 0x23700732,a4
-
- CurApNameTest
- bgt @not_what_we_want
-
- clr.l -(a7)
- pea (a7)
- dc.w 0xA870 // _LocalToGlobal
- tst.l (a7)+
- bne @not_what_we_want
-
- move.l 24(a7),a0 // a0 = dstRect
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
- move.w 4(a0),d0
- sub.w (a0),d0
- cmpi.w #32,d0
- bne @not_what_we_want
-
- lea @junkRect,a0
- move.l a0,24(a7) // replace dstRect with zero so the icon won't show up.
-
- @not_what_we_want:
- movem.l (a7)+,d0/a0/a1/a4
- bra.s @oldPlotCIcon
- @junkRect:
- dc.w 0,0,0,0
- @oldPlotCIcon:
- }
- static asm void oldPlotCIcon(void) {
- jmp 0x12345678
- }
-
-
-
-
- void realmain(Handle code) {
- long *oldTrap;
-
- // if (NewGestalt('IKch', &IconCatcher) != noErr) goto x9;
-
- // sanity checks here
-
- DetachResource(code);
-
- #if 0
- oldTrap = (long *)(2 + (long) &oldSyncWait);
- *oldTrap = (long)GetOSTrapAddress(0xA0B7);
- SetOSTrapAddress((void *)&pSyncWait, 0xA0B7);
- #endif
-
- oldTrap = (long *)(2 + (long) &oldGet1IndRes);
- *oldTrap = (long)GetToolTrapAddress(0xA80E);
- SetToolTrapAddress((void *) &pGet1IndRes, 0xA80E);
-
- oldTrap = (long *)(2 + (long) &oldCloseResFile);
- *oldTrap = (long)GetToolTrapAddress(0xA99A);
- SetToolTrapAddress((void *) &pCloseResFile, 0xA99A);
-
- oldTrap = (long *)(2 + (long) &oldFillRect);
- *oldTrap = (long)GetToolTrapAddress(0xA8A5);
- SetToolTrapAddress((void *) &pFillRect, 0xA8A5);
-
- oldTrap = (long *)(2 + (long) &oldFrameRect);
- *oldTrap = (long)GetToolTrapAddress(0xA8A1);
- SetToolTrapAddress((void *) &pFrameRect, 0xA8A1);
-
- oldTrap = (long *)(2 + (long) &oldCopyMask);
- *oldTrap = (long)GetToolTrapAddress(0xA817);
- SetToolTrapAddress((void *) &pCopyMask, 0xA817);
-
- oldTrap = (long *)(2 + (long) &oldCopyBits);
- *oldTrap = (long)GetToolTrapAddress(0xA8EC);
- SetToolTrapAddress((void *) &pCopyBits, 0xA8EC);
-
- oldTrap = (long *)(2 + (long) &oldPlotIcon);
- *oldTrap = (long)GetToolTrapAddress(0xA94B);
- SetToolTrapAddress((void *) &pPlotIcon, 0xA94B);
-
- oldTrap = (long *)(2 + (long) &oldPlotCIcon);
- *oldTrap = (long)GetToolTrapAddress(0xAA1F);
- SetToolTrapAddress((void *) &pPlotCIcon, 0xAA1F);
- }
-
- #if 0
- pascal OSErr QuickSilver(OSType selector,long *_response) {
- void *oldA4 = SetA4(&main);
- long *response = _response;
-
- switch (selector) {
- case 'QSlv':
- *response = (long)&QuickSilver;
- break;
- case 'Pref':
- *response = (long)&prefs;
- break;
- default:
- SetA4(oldA4);
- return gestaltUnknownErr;
- break;
- }
-
- SetA4(oldA4);
- return noErr;
- }
- #endif
-
-